package com.weng.platform.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.platform.entity.ProjectUserRel;
import com.weng.platform.platform.mapper.ProjectUserRelMapper;
import com.weng.platform.platform.service.IProjectUserRelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * 项目和用户关联 服务实现类
 *
 * @author weng
 * @date 2021-01-15 17:18:44
 *
 */ 
@Slf4j
@Service
public class ProjectUserRelServiceImpl extends BaseServiceImpl<ProjectUserRelMapper, ProjectUserRel> implements IProjectUserRelService {
	@Autowired
	private ProjectUserRelMapper projectUserRelMapper;
	

	/**
	 * 分页查询项目和用户关联
	 * @return
	 */
	@Override
	public IPage<ProjectUserRel> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<ProjectUserRel> qw = new QueryWrapper<>();
		IPage<ProjectUserRel> page = new PageModel<>(pageNo,pageSize);
		return projectUserRelMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个项目和用户关联
	 * @param id
	 * @return
	 */
	@Override
	public ProjectUserRel getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个项目和用户关联
	 * @param projectUserRel
	 * @return
	 */
	@Override
	public ProjectUserRel add(ProjectUserRel projectUserRel)  {
		
		projectUserRelMapper.insert(projectUserRel);
		return projectUserRel;
	}

	/**
	 * 更新单个项目和用户关联
	 * @param projectUserRel
	 * @return
	 * @
	 */
	@Override
	public int update(ProjectUserRel projectUserRel)  {
		
		return projectUserRelMapper.updateById(projectUserRel);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] projectUserRelIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(projectUserRelIds));
		if (flag) {
			return ResponseData.success();
		} else {
			return ResponseData.success();
		}
	}

}
